#include <Python.h>
#include <string.h>
#include "lunar.h"


static PyObject * GetLunarName(PyObject *self, PyObject *args)
{
    //char *fromPython;
	char result[64] = {0};
	struct oneday day;

	if (! PyArg_ParseTuple(args, "(iii)", &(day.year), &(day.month), &(day.date))) {
		return NULL;
	}
	else {
        lunar_in_string(day, result);
        return Py_BuildValue("s", result);
	}
}
static PyObject * GetGlaName(PyObject *self, PyObject *args)
{
	char result[64] = {0};
	struct oneday day;

	if (! PyArg_ParseTuple(args, "(iii)", &(day.year), &(day.month), &(day.date))) {
		return NULL;
	}
	else {
		gla_in_string(day, result);
		return Py_BuildValue("s", result);
	}
}
static PyObject * ToLunar(PyObject * self, PyObject * args)
{
	int y, m, d;
	struct oneday gla, lunar;
	if (! PyArg_ParseTuple(args, "iii", &y, &m, &d))
		return NULL;
	else {
		gla = gen_oneday(y, m, d);
		lunar = gla_to_lunar(gla);
		return Py_BuildValue("(iii)", lunar.year, lunar.month, lunar.date);
	}
}

static PyObject * ToGla(PyObject * self, PyObject * args)
{
	int y, m, d;
	struct oneday gla, lunar;
	if (!PyArg_ParseTuple(args, "iii", &y, &m, &d))
		return NULL;
	else {
		lunar = gen_oneday(y, m, d);
		gla = lunar_to_gla(lunar);
		return Py_BuildValue("(iii)", gla.year, gla.month, gla.date);
	}
}
static PyObject * PackDay(PyObject *self, PyObject *args)
{
	int y, m, d;
	struct oneday day;
	if (!PyArg_ParseTuple(args, "iii", &y, &m, &d))
		return NULL;
	else {
		day = gen_oneday(y, m, d);
		return Py_BuildValue("(iii)", day.year, day.month, day.date);
	}
}
static struct PyMethodDef Lunar_methods[] = {
        {"lunarname", GetLunarName, METH_VARARGS},
		{"glaname", GetGlaName, METH_VARARGS}, 
		{"tolunar", ToLunar, METH_VARARGS},
		{"togla", ToGla, METH_VARARGS},
		{"packday", PackDay, METH_VARARGS},
        {NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC initLunar() {
    (void)Py_InitModule("Lunar", Lunar_methods);
}
